import numpy as np
import cv2 as cv
import matplotlib.pyplot as plt

# 导入加入了椒盐噪声的图像
dogsp = cv.imread("image/dogsp.jpeg")
plt.imshow(dogsp[:, :, ::-1])
plt.show()
# 导入加入了高斯噪声的图像
doggs = cv.imread("image/dogGauss.jpeg")
plt.imshow(doggs[:, :, ::-1])
plt.show()


# 均值滤波(算法简单，计算较快，但是在去除噪声的同时会去除许多细节的东西，将图像变得模糊)(实测：只是变模糊)
dog1 = cv.blur(dogsp, (5, 5))
plt.imshow(dog1[:, :, ::-1])
plt.show()


# 高斯滤波(适用于彩色图像)(实测：也只是变模糊)
dog2 = cv.GaussianBlur(doggs, (3, 3), 1)
plt.imshow(dog2[:, :, ::-1])
plt.show()


# 中值滤波(对椒盐噪声尤其有用)(实测：相比均值滤波，中值滤波处理椒盐噪声效果显著)
dog3 = cv.medianBlur(dogsp, 5)
plt.imshow(dog3[:, :, ::-1])
plt.show()
